function toast(options){
	if(options?.type==='success'){
		toastSuccess(options?.message,options?.susToast);
	}else if(options?.type==='error'){
		toastError(options?.message,options?.errToast);
	}else if(options?.type==='loading'){
		toastLoading(options?.loading);
	}else if(options?.type==='unloading'){
		toastUnloading();
	}else{
		toastError(options?.message)
	}
}

toast['success'] = (message,susToast) => {
	toast({
		type:'success',
		message:message,
		susToast:susToast,
	});
}
toast['error'] = (message,errToast) => {
	toast({
		type:'error',
		message:message,
		errToast:errToast
	});
}
toast['loading'] = (loading) => {
	toast({
		type:'loading',
		loading:loading
	});
}
toast['unloading'] = () => {
	toast({
		type:'unloading'
	});
}

function toastSuccess(message,susToast){
	if(susToast === true){
		uni.showToast({ 
			title:''+message, 
			icon:'none', 
			duration:2000, 
			mask:true ,
		});
	}
}
function toastError(message,errToast){
	if(errToast!==false){
		uni.showToast({ 
			title:''+message, 
			icon:'none', 
			duration:2000, 
			mask:true ,
		});
	}
}
function toastLoading(loading){
	if(loading!==false){
		uni.showToast({
			title: loading ? ''+loading : '加载中', 
			icon:'loading', 
			duration:10000,
			mask:true ,
		})
	}
}
function toastUnloading(){
	try{ uni.hideToast(); }catch(e){ }
}

export default toast;